<?
include_once("codelibrary/inc/variables.php");
include_once("supersession.php");

function query($query,$extra="")
{
	$result = mysql_query($query) or die("Query execution error : ".mysql_error()."<br> Query : $query <br> Query Type : $extra");
	return $result;
}

function packagesList($packageid) {
	$query = "select * from packages";
	$results = query($query);
	
	?>
	<select  name="package_id" id="package_id">
	<option value="0">Select Package</option>
	<?
		while( $row = mysql_fetch_object($results))
		{
			if($packageid == $row->package_id) 
				$select="selected";
			else 
				$select="";
			echo "<option value='".$row->package_id."' $select>".$row->package_name."</option>\n";
		}
	?>
	</select>
	<?
}


$msg = $_GET['msg'];

if($_POST['administrator_id'] && $_POST['package_id']) {

		$query = "update administrator_info set package_id='".$_POST['package_id']."', dateadded=now() where administrator_id='".$_POST['administrator_id']."'";
		query($query);

	$msg = "Package Updated successfully";
	header("location:super-users.php?msg=$msg");
}

$userid = $_REQUEST['userid'];

$query = "select ai.package_id, ai.administrator_id,ai.username,bi.companyname,pk.package_name,pk.access_days, ai.dateadded from administrator_info as ai
		  left join business_info as bi on ai.business_id=bi.business_id
		  left join packages as pk on ai.package_id=pk.package_id
		  where ai.status=1 and administrator_id='$userid'
		  order by dateadded desc";
		  
$res = query($query);
$obj = mysql_fetch_object($res);
if($obj->username=='') {
	header("location:super-users.php?msg=User not found");
}
$currdate = mktime();
$dateadded = strtotime($obj->dateadded);
$days_left = $obj->access_days - ceil( ($currdate-$dateadded)/84600 );
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html dir="LTR" lang="en">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>Online Appointment</title>

<base >
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<title>Staff Management</title>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">

<script>
function validate(frm) {
	if(frm.package_name.value=="") {
		alert("Please enter a package name.")
		return false;
	} else if(frm.access_days.value=="") { 
		alert("Please enter a access days")
		return false;
	} else if(frm.staff_limit.value=="") { 
		alert("Please enter a staff memebers limit.")
		return false;
	}
	
	return true;

}
</script>
<table cellpadding="0" cellspacing="0" border="0"><tr>
  <td style="background:url(images/top.gif) repeat-x top; ">
<table cellpadding="0" cellspacing="0" border="0" style="width:764px" align="center"> 
	<tr>
		<td>
			<table cellpadding="0" cellspacing="0" border="0" style="height:57">
				<tr>
				  <td height="57">&nbsp;</td>
				</tr>
			</table>


		</td>
	</tr>
	<tr>
		<td>





<table border="0" width="105%" cellspacing="0" cellpadding="0">
  <tr>
    <td valign="top" class="col_left">

<table border="0"cellspacing="0" cellpadding="0" class="box_width_left">
	<tr><td width="100%">
		<table border="0" cellspacing="0" cellpadding="0">
<tr><td>

<table border="0" width="100%" cellspacing="0" cellpadding="0" class="">
  <tr>
    <td>
    <table border="0" width="100%" cellspacing="0" cellpadding="0"  class="" height="91">
  <tr>
    <td align="center" height="91">
    <img border="0" src="images/logo.jpg" width="208" height="86"></td>
  </tr>
</table>
</td>
  </tr>
</table>
</td></tr>


          <tr>
            <td>
<table border="0" width="100%" cellspacing="0" cellpadding="0"  class="box_header_txt" height="48">
  <tr>
    <td style="background-image: url(images/1_bg2-2.gif)" height="1">
      <p style="margin-top: 16"> </td>
  </tr>
</table>
<table border="0" width="100%" cellspacing="0" cellpadding="0"   style="border-bottom:12px solid #ffffff;">
  <tr>
    <td>
    <table border="0" width="100%" cellspacing="0" cellpadding="0"  style="margin-bottom:0px;background:#7C7C7C url(images/1_line.gif) no-repeat left bottom;" >
  <tr>
    <td  style="padding:3px 16px 8px 25px;">
      <? include("super-menu.php"); ?>
    </td>
  </tr>
</table>
</td>
  </tr>
</table>
            </td>
          </tr>


          <tr>
            <td class="">&nbsp;
</td>
          </tr>

		</table>
	</td>
	<td><img src="images/spacer.gif" border="0" alt="" width="15" height="1"></td></tr>
</table>

    </td>

    <td width="100%" valign="top">
<table border="0" width="100%" cellspacing="0" cellpadding="0"  class="cont_header_txt">
  <tr>
    <td>
			<table border="0" cellpadding="0" cellspacing="0" bgcolor="#EAEAEA" class="cont_header_txt">
				<tr>
					<td><img src="images/1_q1.gif" border="0" alt="" width="45" height="39"></td>
					<td style="width:100%">ADd  package</td>
					<td><img src="images/1_q2.gif" border="0" alt="" width="10" height="39"></td>
				</tr>
			</table>										 
			</td>
  </tr>
</table>


						
						<table cellpadding="0" cellspacing="0" border="0" style="border:0px solid #DEDEDE; border-width:0px 1px 0px 1px;">
                          <tr>
                            <td style="background:#ffffff;border:0px solid #ffffff; border-width:18px 5px 10px 5px;"><!-- new_products //-->
                                <table border="0" width="" cellspacing="0" cellpadding="0" class="box_width_cont product">
                                  <tr>
                                    <td>
									<form name="packageform" method="post" >
									  <table width="108%" border="1" cellpadding="3" cellspacing="2" bordercolor="#FFDBCA" class="table">
                                        <tr>
                                          <td width="29%" height="27" valign="bottom" class="smallText"><strong>Company Name </strong></td>
                                          <td height="27" colspan="2" valign="top" nowrap class="smallText"><?=$obj->companyname?></td>
                                        </tr>
                                        <tr>
                                          <td height="27" valign="bottom" class="smallText"><strong>Admin Username </strong></td>
                                          <td height="27" colspan="2" valign="top" nowrap class="smallText"><?=$obj->username?></td>
                                        </tr>
                                        <tr>
                                          <td height="27" valign="bottom" class="smallText"><strong>Package Added/Updated on </strong></td>
                                          <td height="27" colspan="2" valign="top" nowrap class="smallText"><?=date("d-M-y",$dateadded)?></td>
                                        </tr>
                                        <tr>
                                          <td height="27" valign="bottom" class="smallText"><p><strong>Days Left</strong></p>                                          </td>
                                          <td height="27" colspan="2" valign="top" nowrap class="smallText"><?=$days_left;?></td>
                                        </tr>
                                        <tr>
                                          <td colspan="3" valign="bottom" class="smallText">&nbsp;</td>
                                        </tr>
                                        
                                        <tr>
                                          <td height="27" valign="bottom" class="smallText">&nbsp;<strong>Package Name </strong></td>
                                          <td height="27" colspan="2" valign="top" nowrap class="smallText"><? packagesList($obj->package_id) ?></td>
                                        </tr>
                                        <tr>
                                          <td height="36" valign="bottom" class="smallText">&nbsp;</td>
                                          <td height="36" colspan="2" valign="top" nowrap class="smallText"><input name="administrator_id" type="hidden" value="<?=$obj->administrator_id?>" size="30"></td>
                                        </tr>
                      
                                        <tr>
                                          <td colspan="3" align="center" valign="middle" class="smallText"><input name="Submit" type="submit" class="button" value="Renew Package" />
                                            &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;
                                            <input name="reset" type="reset" class="button" value="Cancel" onClick="location.href='super-users.php'"/>                                          </td>
                                        </tr>
                                      </table>
									</form>                                 
                                  
                                    </td>
                                  </tr>
                                </table>
                              <table border="0" cellspacing="0" cellpadding="0" align="center" class="box_width_cont product">
                                  <tr>
                                    <td></td>
                                  </tr>
                              </table></td>
                          </tr>
                        </table>
						
						<table cellpadding="0" cellspacing="0" border="0">
							<tr>
								<td><img src="images/1_q4.gif" border="0" alt="" width="10" height="10"></td>
								<td style="width:100%; background-image:url(images/1_li1.gif)"></td>
								<td><img src="images/1_q3.gif" border="0" alt="" width="10" height="10"></td>
							</tr>
						</table>
						


		
		
		</td>

    <td class="col_right">

<table border="0"cellspacing="0" cellpadding="0" class="box_width_right">
	<tr><td></td>
		<td width="100%">
			<table border="0" cellspacing="0" cellpadding="0">
				<tr><td></td></tr>
			</table>
		</td>
	</tr>
</table>


    </td>
  </tr>
</table>



		</td>
	</tr>
	<tr>
		<td>
			<table cellpadding="0" cellspacing="0" border="0" style="height:98px; background-image:url(images/bot.gif)">
				<tr>
					<td>
						<table cellpadding="0" cellspacing="0" border="0" class="footer">
							<tr>									
								<td height="77"><img src="images/spacer.gif" border="0" alt="" width="25" height="1"></td>				
								<td style="width:207px"><br style="line-height:49px"><img src="images/p1.gif" border="0" alt="" width="145" height="24"><br></td>
							  <td style="width:532px">&nbsp;</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
		</td>
	</tr>
</table></td></tr></table>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
  <tr>
    <td align="center"></td>
  </tr>
</table>
</body>

</html>